package org.klarton;

import org.klarton.audio.Capture;
import org.klarton.filter.goertzel.GoertzelFilterBankFactory;
import org.klarton.gui.FrequencyAnalyzerPanel;
import org.klarton.filter.FilterBank;

import javax.sound.sampled.LineUnavailableException;
import javax.swing.*;
import java.awt.*;

/**
 * This is the entry point into the application. It reads the given parameters
 * and configures the application components.
 */
public class Analyzer {

    public static final int SAMPLE_RATE = 8000;

    public static void main(String... args) throws LineUnavailableException {
        final FilterBank bank = GoertzelFilterBankFactory.createFilterBank(440, SAMPLE_RATE);

        JFrame frame = new JFrame("Klarton Realtime Frequency Analyzer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(new FrequencyAnalyzerPanel(bank.getFilters()));
        frame.setSize(new Dimension(800, 600));
        frame.setVisible(true);

        new Capture(bank, SAMPLE_RATE).start();
    }
}
